package com.ed.controller;

import com.ed.domain.ChatConversation;
import com.ed.domain.ChatMessage;
import com.ed.result.Result;
import com.ed.service.IAIService;
import com.ed.vo.AIAnalysisVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/AI")
public class AIController {

    @Autowired
    private IAIService iAIService;

    /**
     * 获取用户答题结果
     * @return
     */
    @GetMapping("/getResponse")
    public Result<AIAnalysisVO> getResponse(){
        return Result.success(iAIService.getResponse());
    }


    //新建一个对话
    @PostMapping("/addChat")
    public Result<String> addChat(@RequestBody ChatConversation chatConversation){
        iAIService.addChat(chatConversation);
        return Result.success("添加成功");
    }

    //删除一个会话
    @PostMapping("/delChat")
    public Result<String> delChat(@RequestBody ChatConversation chatConversation){
        iAIService.delChat(chatConversation);
        return Result.success("删除成功");
    }

    //获取会话列表
    @GetMapping("/getChats")
    public Result<List<ChatConversation>> getChats(){
        List<ChatConversation> chats = iAIService.listChats();
        return Result.success(chats);
    }

    /**
     * 通义千问模型  发起对话
     */
    @PostMapping(value = "/chat")
    public Result<String> chat(@RequestBody ChatMessage chatMessage){
        return Result.success(iAIService.chat(chatMessage));
    }
    /**
     * 会话历史的查询
     */
    @GetMapping(value = "/chatHistory")
    public Result<List<ChatMessage>> chatHistory(String conversationId){
        return Result.success(iAIService.listChatHistory(conversationId));
    }
}
